package com.zsc.newbuds.mapper;

import com.zsc.newbuds.entity.Admin;
import com.zsc.newbuds.entity.MoneyOfWeekVo;
import com.zsc.newbuds.entity.StatisticOfWeekVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author D
 */
public interface AdminMapper {


    @Select("SELECT\n" +
            "\tSUM( sale_money ) sale_money,\n" +
            "\tMONTH ( create_time ) monthly \n" +
            "FROM\n" +
            "\t`saleRecord` \n" +
            "WHERE\n" +
            "\tYEAR ( create_time ) = YEAR(NOW()) \n" +
            "GROUP BY\n" +
            "\tmonthly \n" +
            "ORDER BY\n" +
            "\tmonthly")
    List<MoneyOfWeekVo> listMoneyOfWeekVo();


    /**
     * 获取本周衣服每天的衣服总数
     * @return
     */
    @Select("SELECT\n" +
            "\tDAYOFWEEK(\n" +
            "\tdate_format( recycle_time, '%Y-%m-%d' )) - 1 AS current_week,\n" +
            "\tSUM(clothes_number) statistic \n" +
            "FROM\n" +
            "\trecycle \n" +
            "WHERE\n" +
            "\tYEARWEEK( date_format( recycle_time, '%Y-%m-%d' ), 1 ) = YEARWEEK(\n" +
            "\tnow()) \n" +
            "GROUP BY\n" +
            "\tcurrent_week\n" +
            "\tORDER BY current_week")
    List<StatisticOfWeekVo> listClothStatisticOfWeekVo();


    /**
     * 获取本周衣服每天的衣服重量总数
     * @return
     */
    @Select("SELECT\n" +
            "\tDAYOFWEEK(\n" +
            "\tdate_format( recycle_time, '%Y-%m-%d' )) - 1 AS current_week,\n" +
            "\tSUM(recycle_weight) statistic \n" +
            "FROM\n" +
            "\trecycle \n" +
            "WHERE\n" +
            "\tYEARWEEK( date_format( recycle_time, '%Y-%m-%d' ), 1 ) = YEARWEEK(\n" +
            "\tnow()) \n" +
            "GROUP BY\n" +
            "\tcurrent_week\n" +
            "\tORDER BY current_week")
    List<StatisticOfWeekVo> listWeightStatisticOfWeekVo();

    /**
     * 获取本周衣服每天的书籍总数
     * @return
     */
    @Select("SELECT\n" +
            "\tDAYOFWEEK(\n" +
            "\tdate_format( recycle_time, '%Y-%m-%d' )) - 1 AS current_week,\n" +
            "\tSUM(recycle_number) statistic \n" +
            "FROM\n" +
            "\trecycle \n" +
            "WHERE\n" +
            "\tYEARWEEK( date_format( recycle_time, '%Y-%m-%d' ), 1 ) = YEARWEEK(\n" +
            "\tnow()) \n" +
            "GROUP BY\n" +
            "\tcurrent_week\n" +
            "\tORDER BY current_week")
    List<StatisticOfWeekVo> listBooksNumberStatisticOfWeekVo();



    /**
     * 获取捐赠书的总数量
     * @return
     */
    @Select("SELECT SUM(recycle_number) FROM recycle")
    int getTotalBooksNumber();

    /**
     * 获取回收衣服数量
     * @return
     */
    @Select("SELECT SUM(clothes_number) FROM recycle")
    int getTotalClothesNumber();


    /**
     * 售卖衣服的总金额
     * @return
     */
    @Select("SELECT SUM(saleRecord.sale_money) FROM saleRecord")
    double getTotalAmount();

    /**
     * 售卖衣服的总重量
     * @return
     */
    @Select("SELECT SUM(recycle_weight) FROM recycle")
    double getTotalWeight();

    /**
     * 获取平台用户数
     * @return
     */
    @Select("SELECT COUNT(userId) FROM user")
    int getTotalUsers();



    /**
     * 根据账号获取管理员信息
     * @param account
     * @return
     */
    @Select("select * from admin where account = #{account}")
    Admin getAdminByAccount(String account);

    /**
     * 根据账号获取管理员信息
     * @param adminId
     * @return
     */
    @Select("select * from admin where admin_id = #{adminId}")
    Admin getAdminById(Integer adminId);

    /**
     * 获取work员工所有数据
     * @param position
     * @return
     */
    @Select("select admin_id,account,password,admin_name,phone,oder_number,address from admin where position = #{position}")
    List<Admin> getWorkList(String position);

    /**
     * 获取Admin所有数据
     * @return
     */
    @Select("select * from admin where position != 'admin'")
    List<Admin> getAdminList();

    /**
     * 增加员工
     * @param admin
     */
    @Options(useGeneratedKeys = true,keyProperty = "adminId")
    @Insert("insert into admin(account,password,admin_name,phone,position,oder_number,address,admin_image) values(#{account},#{password},#{adminName},#{phone},#{position},#{oderNumber},#{address},#{adminImage})")
    void addAdmin(Admin admin);


    /**
     * 增加志愿者
     * @param admin
     * @return
     */
    @Options(useGeneratedKeys = true,keyProperty = "adminId")
    @Insert("insert into admin(account,password,admin_name,phone,position,oder_number,address,admin_image) values(#{account},#{password},#{adminName},#{phone},#{position},#{oderNumber},#{address},#{adminImage})")
    void addVolunteer(Admin admin);

    /**
     * 更新头像地址
     * @param adminId
     * @param adminImage
     */
    @Update("update admin set admin_image = #{adminImage} where admin_id = #{adminId}")
    void updateImage(Integer adminId,String adminImage);


    /**
     * 更新员工工作分配状态
     * @param adminId
     * @param workArea
     */
    @Update("update admin set work_area = #{workArea} where admin_id = #{adminId}")
    void updateWorkSate(Integer adminId,String workArea);

    /**
     * 更新全部员工工作分配状态
     * @param workArea 状态
     */
    @Update("update admin set work_area = #{workArea}")
    void updateSate(String workArea);

    /**
     * 修改密码
     * @param admin
     * @return
     */
    @Update("update admin set password = #{password} where account = #{account}")
    void updateAdmin(Admin admin);


    /**
     * 删除管理员账号
     * @param adminId
     */
    @Delete("delete from admin where admin_id = #{adminId}")
    void deleteAdmin(Integer adminId);


    /**
     * 更新工作人員處理訂單數
     * @param id
     * @param oderNumber
     */
    @Update("update admin set oder_number = #{oderNumber} where admin_id = #{id}")
    void updateOderNumber(Integer id,int oderNumber);





}
